package cn.drew.org.service.impl;

import cn.drew.basic.utils.PageList;
import cn.drew.org.domain.SystemDictionaryType;
import cn.drew.org.mapper.SystemDictionaryDetailMapper;
import cn.drew.org.mapper.SystemDictionaryTypeMapper;
import cn.drew.org.query.SystemDictionaryTypeQuery;
import cn.drew.org.service.SystemDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class SystemDictionaryTypeServiceImpl implements SystemDictionaryTypeService {

    @Autowired
    private SystemDictionaryTypeMapper systemDictionaryTypeMapper;
    @Autowired
    private SystemDictionaryDetailMapper systemDictionaryDetailMapper;
    @Override
    public void add(SystemDictionaryType systemDictionaryType) {
        systemDictionaryTypeMapper.add(systemDictionaryType);
    }

    @Override
    public void update(SystemDictionaryType systemDictionaryType) {
        systemDictionaryTypeMapper.update(systemDictionaryType);
    }

    @Override
    public void delete(Long id) {

        systemDictionaryDetailMapper.deleteByType(id);

        systemDictionaryTypeMapper.delete(id);

    }

    @Override
    public SystemDictionaryType findById(Long id) {
        return systemDictionaryTypeMapper.findById(id);
    }

    @Override
    public List<SystemDictionaryType> findAll() {
        return systemDictionaryTypeMapper.findAll();
    }



    @Override
    public PageList<SystemDictionaryType> queryByPage(SystemDictionaryTypeQuery systemDictionaryTypeQuery) {
        Integer count = systemDictionaryTypeMapper.queryByCount(systemDictionaryTypeQuery);
        if (count == 0 || count == null){
            return new PageList(0,new ArrayList());
        }else{
            List<SystemDictionaryType> systemDictionaryTypes = systemDictionaryTypeMapper.queryByPage(systemDictionaryTypeQuery);
            return new PageList<SystemDictionaryType>(count,systemDictionaryTypes);
        }

    }

    @Override
    public void patchDelete(List<Long> ids) {
        systemDictionaryDetailMapper.patchDeleteByType(ids);
        systemDictionaryTypeMapper.patchDelete(ids);
    }

//    @Override
//    public List<SystemDictionaryType> findByDeptid(Long deptid) {
//        List<SystemDictionaryType> systemDictionaryTypes = systemDictionaryTypeMapper.findAll();
//        System.out.println(deptid);
//        //将departmentId 和deptid 相等的数据过滤 ,再转化为list
//        return systemDictionaryTypes.stream().filter(emp -> deptid.equals(emp.getDepartmentId())).collect(Collectors.toList());
//
//    }
}
